package com.empire.module.sporttery.service.football500yazcount;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.empire.module.sporttery.controller.admin.football500yazcount.vo.*;
import com.empire.module.sporttery.dal.dataobject.football500yazcount.Football500YazCountDO;
import com.empire.framework.common.pojo.PageResult;
import com.empire.framework.common.pojo.PageParam;
import com.empire.framework.common.util.object.BeanUtils;

import com.empire.module.sporttery.dal.mysql.football500yazcount.Football500YazCountMapper;

import static com.empire.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.empire.module.sporttery.enums.ErrorCodeConstants.*;

/**
 * 亚盘实时表统计 Service 实现类
 *
 * @author 无敌仙人
 */
@Service
@Validated
public class Football500YazCountServiceImpl implements Football500YazCountService {

    @Resource
    private Football500YazCountMapper football500YazCountMapper;

    @Override
    public Integer createFootball500YazCount(Football500YazCountSaveReqVO createReqVO) {
        // 插入
        Football500YazCountDO football500YazCount = BeanUtils.toBean(createReqVO, Football500YazCountDO.class);
        football500YazCountMapper.insert(football500YazCount);
        // 返回
        return football500YazCount.getId();
    }

    @Override
    public void updateFootball500YazCount(Football500YazCountSaveReqVO updateReqVO) {
        // 校验存在
        validateFootball500YazCountExists(updateReqVO.getId());
        // 更新
        Football500YazCountDO updateObj = BeanUtils.toBean(updateReqVO, Football500YazCountDO.class);
        football500YazCountMapper.updateById(updateObj);
    }

    @Override
    public void deleteFootball500YazCount(Integer id) {
        // 校验存在
        validateFootball500YazCountExists(id);
        // 删除
        football500YazCountMapper.deleteById(id);
    }

    private void validateFootball500YazCountExists(Integer id) {
        if (football500YazCountMapper.selectById(id) == null) {
            throw exception(FOOTBALL500_YAZ_COUNT_NOT_EXISTS);
        }
    }

    @Override
    public Football500YazCountDO getFootball500YazCount(Integer id) {
        return football500YazCountMapper.selectById(id);
    }

    @Override
    public PageResult<Football500YazCountDO> getFootball500YazCountPage(Football500YazCountPageReqVO pageReqVO) {
        return football500YazCountMapper.selectPage(pageReqVO);
    }

}